//
//  YDOAEditStockVC.swift
//  YDOAProduct
//
//  Created by 占益民 on 2017/11/23.
//  Copyright © 2017年 Allen. All rights reserved.
//

import UIKit
import Toaster
class YDOAEditStockVC: UIViewController {
    @IBOutlet weak var danjialb: UITextField!
    
    @IBOutlet weak var remarkNumTF: UITextField!
    @IBOutlet weak var goodsTypeLb: UILabel!
    @IBOutlet weak var goodsNameLb: UILabel!
    var model : YDOAStockModel?
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "修改信息"
        self.navigationController?.navigationBar.isHidden = false
        self.automaticallyAdjustsScrollViewInsets = false
        self.edgesForExtendedLayout = .init(rawValue: 0)
        
        if self.model != nil {
            remarkNumTF.text = model?.number ?? ""
            goodsNameLb.text = "物品名称:\(model?.name ?? "")"
            if model?.x_type == "1"{
                goodsTypeLb.text = "物品类型:办公用品"
            }else if model?.x_type == "2"{
                goodsTypeLb.text = "物品类型:劳保用品"
            }else{
                goodsTypeLb.text = "物品类型:招待用品"
            }
            
            danjialb.text = model?.unit ?? ""
        }

        // Do any additional setup after loading the view.
    }
    
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true)
    }
    
    
//    点击确定修改
    @IBAction func sureBtnClick(_ sender: Any) {
        view.endEditing(true)
        if !(danjialb.text  == "") || !(remarkNumTF.text == "") {
            let urlStr = String(format:EDIT_STOCK,(model?.id)!,remarkNumTF.text!,danjialb.text!)
//            let params = ["pid":model?.id,"num":remarkNumTF.text,"unit":danjialb.text];
            YMNetworkManager().getRequest(urlString: urlStr, params: nil, success: { (responser) in
                if responser["status"]?.int8Value == 1{
                    Toast(text: responser["message"] as? String, delay: 0, duration: 1.5).show()
                    self.navigationController?.popViewController(animated: true)
                    
                }else{
                  Toast(text: responser["message"] as? String, delay: 0, duration: 1.5).show()
                }
              
            }, failture: { (error) in
                
            })
        }else{
            Toast(text: "填写内容不能为空", delay: 0, duration: 1.5).show()
        }
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
}


extension  YDOAEditStockVC : UITextFieldDelegate {
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.returnKeyType = .done
        textField.resignFirstResponder()
        return true
    }
}


